package com.yuanthink.gwt.client.workplace;

import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.yuanthink.gwt.client.eventbus.EventBus;
import com.yuanthink.gwt.client.registry.WindowRegistry;
import com.google.gwt.user.client.Element;

/**
 * 
 * @author 06peng
 *
 */
public class Navigator extends ContentPanel {
	
	ColumnTreePanel mainArea = null;
    ToolBar toolBar = new ToolBar();
    EventBus eventBus;
    ContentPanel center = new ContentPanel();
    ContentPanel info = new ContentPanel();
    Button exitButton;

	public Navigator(EventBus eventBus) {
        toolBar.setBorders(false);
        this.setHeading("<div style='text-align:center'>" + "工作台" + "</div>");
        this.setId("navigator");
        this.setTopComponent(toolBar);
        this.setLayout(new FitLayout());
        this.setBodyBorder(false);

        info.setBodyBorder(false);
        info.setBorders(false);
        info.setHeading("<div style='text-align:center'>" + "平台活动状态" + "</div>");
        info.setLayout(new FitLayout());
        
        this.setId("navigator");
        this.setStateful(true);

        this.eventBus = eventBus;
        this.setLayout(new FitLayout());

        BorderLayoutData centerData = new BorderLayoutData(Style.LayoutRegion.CENTER);
        centerData.setMargins(new Margins(0));
        center.setLayout(new FitLayout());
        center.setScrollMode(Style.Scroll.NONE);
        this.add(center);
        
//      BorderLayoutData southData = new BorderLayoutData(Style.LayoutRegion.SOUTH, 220);
//      southData.setSplit(true);
//      southData.setCollapsible(true);
//      southData.setFloatable(true);
//      southData.setMargins(new Margins(0));

//      Frame infoFrame = new Frame();
//      infoFrame.setUrl(DOM.getElementById("backEndPath").getAttribute("value")+"/OurHome/modules/noprivilege/platformforactive.jsp?merchantId="+AppGlobal.merchantId);
//      DOM.setIntAttribute(infoFrame.getElement(), "frameBorder", 0);
//
//      info.add(infoFrame);
//      this.add(info, southData);
      //borderLayout.collapse(Style.LayoutRegion.SOUTH);
    }
	
	public void setCurrentWorkspace(ModelData config) {
		ColumnTreePanel treePanel = (ColumnTreePanel) WindowRegistry.getWindow("columnPanel", null);
		treePanel.setEventBus(eventBus);
		if (mainArea != null) {
			center.remove(mainArea);
		}
		String name = config.get("name");
		center.setHeading(name);
		center.add(treePanel);
		mainArea = treePanel;
		center.layout(true);
	}
	
	protected void onRender(Element parent, int pos) {
		super.onRender(parent, pos);
	}

	public TreePanel<ModelData> getTreePanel() {
		return mainArea.getTree();
	}
	
}
